home *** CD-ROM | disk | FTP | other *** search
- set output error
-
- display _new in blue /*
- */ "Loading Survive.Kit Release 2.0 Demonstration Version" _n /*
- */ "Copyright (c) 1987-1988 by ==C=R=C==. All rights reserved."
-
-
- /*
- User's wishing to edit Survive.Kit please see comments at end of this file.
- */
-
-
- * Kaplan-Meier estimates
-
-
- capture program drop kapmeier
- program define kapmeier
- di in blue "not available in demonstration version"
- end
-
- * greenwood's formula
-
- capture program drop gwood
- program define gwood
- di in blue "not available in demonstration version"
- end
-
-
- cap program drop loglogs
- program define loglogs
- if "%_*"=="" {
- di in blu "loglogs survtime deadind [, title(string)]"
- exit
- }
- mac def _options "Title(string) BY(string) *"
- mac def _varlist "req ex"
- mac def _if "opt"
- mac def _in "opt"
- parse "%_*"
- parse "%_varlist", parse(" ")
- capture {
- if "%_title"=="" {
- mac def _title " Log-Log Survival Check for Weibull"
- }
- if "%_by"!="" {
- mac def _byy "by(%_by)"
- }
- if "%_if`%_in"~="" {
- keep %_if %_in
- }
- _survc %_1 %_2 %_by
- gen _lls = log(-log(_surv))
- gen _lt = log(%_1)
- format _lls %9.0f
- graph _lls _lt, title("%_title") %_options %_byy /*
- */ l1("log(-log(survival))") b2("log(time)")
-
- }
- cap drop _lt
- cap drop _surv
- cap drop _stds
- cap drop _vlogs
- cap drop _lls
- end
-
- /*
- Part 2 - Survival Curve Calculations
- */
-
-
- capture program drop _survc
- program define _survc
- mac def _varlist "req ex"
- mac def _if "opt"
- mac def _in "opt"
- parse "%_*"
- cap drop _xi
- cap drop _surv
- cap drop _stds
- cap drop _vlogs
- capture {
- if "%_3"!="" {
- mac def _byc "by %_3:"
- }
- gen _stds = - %_2
- sort %_3 %_1 _stds /* deaths first */
- gen int _xi = 0
- %_byc replace _xi = 1 %_if %_in
- %_byc replace _xi = sum(_xi)
- %_byc replace _xi = _xi[_N] + 1 - _xi
- gen _surv = 1
- replace _surv = (_xi - %_2) / _xi %_if %_in
- %_byc replace _surv = _surv * _surv[_n-1] if _n>1
- by %_3 %_1: replace _surv = _surv[_N]
- label var _surv "Survival Probability"
- replace _stds = %_2 / _xi / (_xi - 1)
- replace _xi=-1 %if %in /* -1 ==> in the sample */
- replace _stds=0 if _xi!=-1
- %_byc gen _vlogs = sum(_stds)
- by %_3 %_1: replace _vlogs = _vlogs[_N]
- replace _surv=. if _xi!=-1
- replace _vlogs=. if _xi!=-1
- replace _stds = _surv*sqrt(_vlogs)
- label var _stds "Greenwood Survival S.D."
- label var _vlogs "Var(log(_surv))"
- drop _xi
- }
- if _rc {
- di in red "--Break--"
- }
- end
-
- capture program drop survcurv
- program define survcurv
- if "%_*"=="" {
- di in blu /*
- */ "survcurv time_variable death_indicator[, by(varname)]"
- exit
- }
- mac def _varlist "req ex"
- mac def _options "BY(string)"
- mac def _if "opt"
- mac def _in "opt"
- parse "%_*"
- parse "%_varlist", parse(" ")
- _survc %_1 %_2 %_by %_in %_if
- if _rc==0 {
- di in bl _new "Variables created:"
- desc _stds _surv _vlogs
- }
- if _rc {
- di in red "--Break--"
- BREAK
- }
- end
-
- capture program drop survsum
- program define survsum
- di in blue "not availble in demonstration version"
- end
-
- /*
- Cox Regression Adjunct
- */
-
- capture program drop _coxvar
- program define _coxvar
- mac def _varlist "req ex"
- mac def _in "opt"
- mac def _if "opt"
- parse "%_*"
- parse "%_varlist", parse(" ")
- cap drop _rh
- cap drop _temp
- cap drop _rh1
- cap drop baserelh
- cap drop ownsurv
- cap drop basesurv
- cap drop basehaz
- capture {
- predict _rh /* we'd like to know its cox */
- cap gen _temp = -%_1
- sort _temp %_2
- gen _rh1 = sum(_rh)
- by _temp: replace _rh1=_rh1[_N]
- gen baserelh = 1
- replace baserelh = exp(-%_2/_rh1) %_if %_in
- label var baserelh "Cox Baseline Relative Hazard"
- replace _temp = - %_2
- sort %_1 _temp
- replace _temp = 99 %_if %_in
- gen basesurv = baserelh
- replace basesurv = basesurv * basesurv[_n-1] if _n>1
- label var basesurv "Cox Baseline Survival Prob"
- by %_1: replace basesurv = basesurv[_N]
- replace basesurv=. if _temp!=99
- replace baserelh=. if _temp!=99
- gen ownsurv = basesurv ^ _rh
- label var ownsurv "Survival Probability"
- }
- if _rc==1 {
- di in red "--- Break ---"
- cap drop basesurv
- cap drop basehaz
- cap drop baserelh
- cap drop _rh
- cap drop _temp
- cap drop _rh1
- BREAK
- }
- cap drop _rh
- cap drop _temp
- cap drop _rh1
- end
-
- capture program drop coxvar
- program define coxvar
- if "%_*"=="" {
- di in blu "coxvar survtime deadind"
- exit
- }
- mac def _varlist "req ex"
- mac def _in "opt"
- mac def _if "opt"
- parse "%_*"
- parse "%_varlist", parse(" ")
- capture _coxvar %_1 %_2 %_if %_in
- if _rc==0 {
- di in bl _new "Variables created:"
- desc baserelh basesurv ownsurv
- }
- end
-
- cap program drop coxbase
- program define coxbase
- if "%_*"=="" {
- di in blu "coxbase survtime deadind [, title(string)]"
- exit
- }
- mac def _options "Title(string) *"
- mac def _varlist "req ex"
- mac def _in "opt"
- mac def _if "opt"
- parse "%_*"
- parse "%_varlist", parse(" ")
- capture {
- if "%_title"=="" {
- mac def _title " Baseline Survival Curve"
- }
- if "%_offset"=="" {
- mac def _myaxis "noaxis xline(0) yline(0)"
- }
- _coxvar %_1 %_2 %_if %_in
- graph basesurv %_1, c(l) title("%_title") /*
- */ ysca(0,1) xsca(0,.) ytic(0,.25,.5,.75,1) %_options
- }
- cap drop basesurv
- cap drop baserelh
- cap drop ownsurv
- end
-
- cap program drop coxhaz
- program define coxhaz
- if "%_*"=="" {
- di in blu "coxhaz survtime deadind [, title(string)]"
- exit
- }
- mac def _options "Title(string) *"
- mac def _varlist "req ex"
- mac def _in "opt"
- mac def _if "opt"
- parse "%_*"
- parse "%_varlist", parse(" ")
- capture {
- if "%_title"=="" {
- mac def _title " Baseline Hazard Function Estimate"
- }
- _coxvar %_1 %_2 %_if %_in
- gen _b1 = %_1==%_1[_n-1]
- replace _b1 = 1 if basesurv==basesurv[_n-1]
- gen _t1 = 1
- replace _t1 = 0 %_if %_in /* work across deleted obs */
- replace _b1 = 1 if _t1==1
- replace _t1 = %_1
- replace _t1 = 0 if _n==1
- replace _t1 = _t1[_n-1] if _b1
- gen _t2 = basesurv
- replace _t2 = 1 if _n==1
- replace _t2 = _t2[_n-1] if _b1
- gen basehaz = (_t2[_n-1]-_t2)/_t2[_n-1]/(_t1-_t1[_n-1]) if !_b1
- label var basehaz "Cox Baseline Hazard Rate"
- graph basehaz %_1, title("%_title") /*
- */ ysca(0,.) xsca(0,.) xlabel ylabel %_options
- drop _b1 _t1 _t2
- di in blu _new "Variables created:"
- noisily desc baserelh basesurv ownsurv basehaz
- exit
- }
- di in red "--Break--"
- cap drop _b1
- cap drop _t1
- cap drop _t2
- cap drop basrelh
- cap drop basesurv
- cap drop ownsurv
- cap drop basehaz
- end
-
- /*
- Part 3: Log Rank Test(s)
- */
-
-
- capture program drop logrank
- program define logrank
- di in blue "not available in demonstration version"
- end
-
-
- capture program drop mantel
- program define mantel
- di in blue "not available in demonstration version"
- end
-
-
- capture program drop wilcoxon
- program define wilcoxon
- di in blue "not available in demonstration version"
- end
-
-
- di
- di in gr "The following new commands are now available:"
- di " coxbase gwood loglogs mantel survsum"
- di " coxhaz kapmeier logrank survcurv wilcoxon"
- di " coxvar"
- di _n in gr "See " in wh "help survive.kit" in gr "."
- exit
-
- Notes to User's wishing to edit this file:
-
- These comments are placed at the end of the file, after the exit, so that
- Stata does not have to read through them every time the user types "run
- Survive.Kit"
-
- Feel free to edit this file and delete programs in which you have no interest.
- Before editing this file, however, make sure the the original is BACKED UP.
- Please do not remove the copyright notice at the top of this file.
-
- If you do edit the file, you should add a display command at the top of this
- file indicating that you have edited the file. You should change the display
- just above these comments that lists the new commands now available.
-
- All utility programs start with an underscore '_'.
-
- Some programs use other programs in achieving the desired result. Review the
- table below carefully before deleting programs.
-
- Program Requires
- --------------------------
- coxbase _coxvar
- coxhaz _coxvar
- coxvar _coxvar
- gwood _survc
- kapmeier _stemp1 _survc
- loglogs _survc
- logrank
- mantel
- survcurv _survc
- survsum _survc
- wilcoxon
-
- For instance, if you deleted the _coxvar program, you would break coxbase,
- coxhaz, and coxvar.
-
- <end of Survive.Kit>